/**
 * 
 */
package ma.hamada.model;

import javax.swing.event.EventListenerList;

import ma.hamada.Listener.PuzzleListener;
import ma.hamada.event.PuzzleChangedEvent;


/**
 * @author M.ABDELOUHAB
 * 
 */
public class PuzzleModel {
	
	private EventListenerList listeners;

	/*
	 * puzzle
	 */
	private int[][] puzzle = new int[4][4];

	/**
	 * 
	 */
	public PuzzleModel(int puzzle[][]) {
		this.puzzle=puzzle;
	}

	/**
	 * @return the puzzle
	 */
	public int[][] getPuzzle() {
		return puzzle;
	}

	/**
	 * @param puzzle the puzzle to set
	 */
	public void setPuzzle(int[][] puzzle) {
		this.puzzle = puzzle;
	}
	
	public void addPuzzleListener(PuzzleListener listener){
		listeners.add(PuzzleListener.class, listener);
	}
	
	public void removePuzzleListener(PuzzleListener pl){
		 listeners.remove(PuzzleListener.class, pl);
	}
	
	public void firePuzzleChanged(){
		PuzzleListener[] listenerList = (PuzzleListener[])listeners.getListeners(PuzzleListener.class);
		
		for(PuzzleListener listener : listenerList){
			listener.puzzleChanged(new PuzzleChangedEvent(this));
		}
	}

}
